﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ElfTyping.Animations;
using Microsoft.Xna.Framework;
using ElfTyping.General;

namespace ElfTyping.Cards
{
    public enum Rarity
    {
        Common = 0,
        Uncommon,
        Rare
    }

    public class Card
    {
        const int Width = 200;
        const int Height = 285;

        protected static Animation ForestCardBase = new Animation(@"Textures\Cards\Base_Forest");
        protected static Animation FireCardBase = new Animation(@"Textures\Cards\Base_Fire");
        protected static Animation OceanCardBase = new Animation(@"Textures\Cards\Base_Ocean");
        protected static Animation SkyCardBase = new Animation(@"Textures\Cards\Base_Sky");
        protected static Animation[] RarityImages = {
                                                        new Animation(@"Textures\Cards\Rarity_Common"),
                                                        new Animation(@"Textures\Cards\Rarity_Uncommon"),
                                                        new Animation(@"Textures\Cards\Rarity_Rare")
                                                    };
        protected static Animation IndicatorSpell = new Animation(@"Textures\Cards\Indicator_Spell");
        protected static Animation IndicatorPassive = new Animation(@"Textures\Cards\Indicator_Passive");
        protected static Animation IndicatorArrow = new Animation(@"Textures\Cards\Indicator_Arrow");
        protected static Animation IndicatorHarem = new Animation(@"Textures\Cards\Indicator_Harem");
        protected static Animation BackImage = new Animation(@"Textures\Cards\Card_Back");

        //protected static Rectangle IndicatorRectangleBase = new Rectangle(0, 0, 24, 24);       
        protected static Rectangle IndicatorRectangleBase = new Rectangle(0, 0, 36, 36);

        protected static Rectangle ImageRectangleBase = new Rectangle(7, 28, 185, 133);        

        protected static Rectangle RarityRectangleBase = new Rectangle(168, 250, 24, 24);

        public string Name { get; protected set; }
        public string Description { get; protected  set; }
        public Animation Image { get; protected set; }
        public Rarity Rarity { get; protected set; }
        public string ID { get; set; }

        public bool IsShowingFront { get; set; }

        protected Animation Indicator;
        protected Animation Base;

        public Card()
        {
            Name = "Empty Card";
            Description = "This does nothing!";
            Image = new Animation(@"Textures\CampState\Camp_Background_4_3");
            Rarity = Rarity.Common;
            ID = "EMPTYCARD";

            IsShowingFront = true;
        }

        public void Draw(Camera camera, Point center)
        {            
            Point topLeft = new Point(center.X - Width / 2, center.Y - Height / 2);
            Rectangle baseRect = new Rectangle(topLeft.X, topLeft.Y, Width, Height);

            if (!IsShowingFront)
            {
                BackImage.Draw(camera, baseRect);
                return; // Draw nothing more!
            }

            Base.Draw(camera, baseRect);

            Rectangle imageRect = ImageRectangleBase;
            imageRect.Offset(topLeft);
            Image.Draw(camera, imageRect);

            Rectangle indicatorRectangle = IndicatorRectangleBase;
            indicatorRectangle.Offset(topLeft);
            Indicator.Draw(camera, indicatorRectangle);

            Rectangle rarityRectangle = RarityRectangleBase;
            rarityRectangle.Offset(topLeft);
            RarityImages[(int)Rarity].Draw(camera, rarityRectangle);

            camera.MakeText(Name)
                .WithTopLeftPosition(topLeft.X + 37, topLeft.Y + 4)
                .WithColor(Color.Black)
                .WithoutShadows()
                .Draw();
            camera.MakeText(Description)
                .WithTopLeftPosition(topLeft.X + 10, topLeft.Y + 183)
                .WithColor(Color.Black)
                .WithoutShadows()
                .Draw();
        }
    }
}
